package player

import (
	"server/cfg"
	"strconv"
)

func EnAddUserExp(uid string, exp int) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	playerCheck, err := getPlayerFromDatabase(uid, "uid")
	if err != nil {
		return ret, err
	}
	playerCheck.Exp += exp
	ret["can_up"] = 0
	roleLevel := cfg.ConfigData.TbRoleLevel.Get(int32(playerCheck.Level + 1))
	zuanSU, _ := strconv.Atoi(roleLevel.ZhuanSu)
	if int(roleLevel.YueLi) <= playerCheck.Exp && int32(zuanSU) <= GetUserZhuanSun(uid) {
		ret["can_up"] = 1
	}
	ret["player_info"] = playerCheck
	return ret, nil
}
func EnCostUserXuanChuanTiLi(uid string, chuanTiLI int) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	playerCheck, err := getPlayerFromDatabase(uid, "uid")

	if err != nil {
		return ret, err
	}

	playerCheck.XuanChuanTiLi -= chuanTiLI
	err = UpdateXuanChuanTilI(uid, playerCheck.XuanChuanTiLi)
	if err != nil {
		return ret, err
	}
	ret["player_info"] = playerCheck
	return ret, nil
}
func EnAddUserXuanChuanTiLi(uid string, chuanTiLI int) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	logic := NewPlayerLogic()
	playerCheck, err := logic.getPlayerFromDatabase(uid, "uid")

	if err != nil {
		return ret, err
	}

	playerCheck.XuanChuanTiLi += chuanTiLI
	err = logic.UpdateXuanChuanTilI(uid, playerCheck.XuanChuanTiLi)
	if err != nil {
		return ret, err
	}
	ret["player_info"] = playerCheck
	return ret, nil
}
func EnChangeUserShouChong(uid string, shouChong []ShouChong) error {
	logic := NewPlayerLogic()
	return logic.UpdateUserShouChong(uid, shouChong)
}
func EnGetUserInfo(uid string) (Player, error) {
	logic := NewPlayerLogic()
	playerCheck, err := logic.getPlayerFromDatabase(uid, "uid")
	if err != nil {

	}
	return playerCheck, nil
}
func EnGetUserList(uid []string) ([]Player, error) {
	logic := NewPlayerLogic()
	playerCheck, err := logic.getPlayerListFromDatabase(uid)
	if err != nil {

	}
	return playerCheck, nil
}
func EnJoinUnion(uid string, uId int32) error {
	return JoinUnion(uid, uId)
}
func EnUserZuanSu(userId string) float64 {
	return 100
}
func EnAddUserVipDianShu(userId string, vipDianShu int32, vip int) {
	dao := NewPlayerDao()
	dao.updateVipDianShu(userId, vipDianShu, vip)
}
